var jsonobj1=""
var  resultiowk={};
var newdata=""
var oldstart=""
var customerTypes=""
var customerIdss=""
var customercodess=""
var inputmm=""
var inputid=""
var inputcode=""
var inputmsg=""
//合同信息详情
contractxixi()
function contractxixi() {
    $.ajax({
        /*root.inter.findContractInfoByPage*/
        url: root.inter.findContractInfoByPage,
        cache: false,  //禁用缓存
        type: "POST",
        async:false,
        dataType:'json',
        data: {
            "pageNum":1,
            "pageSize":10,
            "contractNum" :getQueryString('contractNum'),
            "customerCode":getQueryString('customerCode'),

        },
        success: function (data) {
            if(data.data.result&& data.data.result.length>0){
                $.each(data.data.result,function(k,v){
                    if (v.customerType=='商店') {
                        $("#jiage").html('分销批发价')
                    }else {
                        $("#jiage").html("批发价");
                    }
                    oldstart=v
                    customerTypes= v.customerType
                    console.log(customerTypes)
                    customerIdss=v.customerId
                    customercodess=v.customerCode
                    sessionStorage.setItem("customerId",customerIdss);
                    sessionStorage.setItem("customerCode",customercodess);
                    sessionStorage.setItem("contractNum",v.contractNum);
                    console.log(v)
                    $('#contractNum').html(v.contractNum)
                    $('#oldSysContractNum').html(v.oldSysContractNum)
                    $('#contractType').html(v.contractType)
                    $('#customerBelongGroupName').html(v.customerBelongGroupName)
                    $('#oldContractState').html(v.oldContractState)
                    $('#customerName').html(v.customerName)
                    $('#conStartDate').html(v.conStartDate)
                    $('#conEndDate').html(v.conEndDate)
                    $('#ftotalmount').html(v.ftotalmount)
                    $('#credit').html(v.credit)
                    $('#tickQuota').html(v.tickQuota)
                    $('#balanceWay').html(v.balanceWay)
                    $('#fcontractcontent').html(v.fcontractcontent)
                    if(v.settleCycleFirst!=""||v.settleCycleSecond!=""||v.settleCycleThird!=""){
                        if(v.settleCycleFirst==1){
                            $('#settlecyclesecond').html('当月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==2){
                            $('#settlecyclesecond').html('次月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==3){
                            $('#settlecyclesecond').html('第三个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==4){
                            $('#settlecyclesecond').html('第四个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==5){
                            $('#settlecyclesecond').html('第五个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }else if(v.settleCycleFirst==6){
                            $('#settlecyclesecond').html('第六个月'+v.settleCycleSecond+'日前,结算'+v.settleCycleThird+'日之前所有货款')
                        }


                    }else {
                        $('#settlecyclesecond').html("")
                    }
                    $('#checkoutCycle').html(v.checkoutCycle)

                })
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}


function upLoadFile() {
    $("#fileUp").trigger('click');
}
//上传文件
function putDataToPage() {
    /*渲染spu sku值到页面*/
    var formData = new FormData();
    formData.append("customerCode", getQueryString('customerCode'));//客户编码  customerCode
    formData.append("customerId", customerIdss);//客户ID customerId
    formData.append("contractNum", getQueryString('contractNum'));//云采合同号 contractNum
    formData.append("createName", JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name);//当前用户名 createName
    formData.append('file', $("#fileUp")[0].files[0]);//Excel文件
    $.ajax({
        url: root.inter.excelImport,
        cache: false,  //禁用缓存
        type: "POST",
        // 告诉jQuery不要去处理发送的数据
        processData: false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType: false,
        data: formData,
        success: function (data) {
            console.log(data)
            if(data.errorCode==1){
                $.Huimodalalert(data.msg,2000);
            }else if(data.errorCode==0){
                if(data.successList.length>0 && data.failList.length==0){
                    $.Huimodalalert(data.msg, 2000);
                    web.dan_detail_list();
                    seahsdfs();

                }else if(data.successList.length>0 && data.failList.length>0){
                    $.Huimodalalert('有重复数据已覆盖!', 2000);
                }
            }
        },
        error: function () {
            $.Huimodalalert('系统异常-请联系管理员！',2000);
        }
    });
}

web.dan_detail_list = (function () {
    return function (page, current, obj, scrollLoad) {
        var cust_data = {
            pageNum:1,
            pageSize:20,
            customerCode:getQueryString('customerCode'),
            contractNum:getQueryString('contractNum'),
            "modifyPriceWay":40

        };
        var succCallBack = function (data, status, response) {
            /*表格渲染*/
            var dataSource = new Array();
            //table的数据源
            var table;   //table对象
            dataSource = [];

            function detaiist(data) {
               console.log(data.data.result)
                newdata=data
                dataSource.splice(0, dataSource.length);//清空数组

                if(data.data.result !=""){
                $.each(data.data.result, function (i, field) {
                    var rowData = new Array();
                    rowData.push(field.productCode);
                    rowData.push(field.imgUrl);
                    rowData.push(field.brand);
                    rowData.push(field.productName);
                    rowData.push(field.saleAttriValue);
                    rowData.push(field.areaName);
                    rowData.push(field.prices);
                    rowData.push(field.unitName);
                    rowData.push(field.modifyPriceWay);
                    rowData.push(field.contractCategoryDiscountId);
                    rowData.push(field.categoryDiscount);
                    dataSource.push(rowData);
                });
                }
                initDataTable(dataSource);

                function initDataTable(dataSource) {
                    var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
                    dttable.fnClearTable(); //清空一下table
                    dttable.fnDestroy(); //还原初始化了的datatable
                    $("#datatable").DataTable({
                        "order": [[ 1, "desc" ]],
                        "autoWidth": false,
                        "ordering": false,
                        "searching": false,
                        "paging": false,
                        "retrieve": true,
                        "destroy": true,
                        "bAutoWidth": true,
                        "bLengthChange": true,
                        "aLengthMenu": [5, 10, 25, 50],
                        "oLanguage": {
                            "sLengthMenu": "每页显示 _MENU_ 条记录",
                            "sZeroRecords": "抱歉， 没有找到",
                            "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                            "sInfoEmpty": "没有数据",
                            "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                            "oPaginate": {
                                "sFirst": "首页",
                                "sPrevious": "前一页",
                                "sNext": "后一页",
                                "sLast": "尾页"
                            },
                            "sZeroRecords": "没有检索到数据",
                            "sProcessing": "<img src='./loading.gif' />",
                        },
                        data: dataSource,
                        columnDefs: [
                            {
                                "visible": true,
                                "targets": 0
                            },
                            {
                                "render": function(data, type, row, meta) {
                                    var val = '<span><td><input class="spuId" type="checkbox" name="spuId" value = "' + row[9] + '">' + row[0] + '</td></span>';
                                    return val;
                                },
                                "targets": 0
                            },
                            {
                                "render": function(data, type, row, meta) {
                                    var val =""
                                    if(row[1]!=""){
                                        val = "<img style='width: 50px; height:50px;' onclick=picShow('查看图片','../../html/goods/picShow.html','"+row[1]+"','500','300','110') src='"+row[1]+"'>";

                                    }else {
                                        val =""
                                    }

                                    return val;
                                },
                                "targets": 1
                            },
                            {
                                "render": function(data, type, row, meta) {
                                    var val = '';
                                    if(customerTypes=='商店'){



                                        if(row[6] && row[6].length>0){
                                            $.each(row[6],function(k,v){
                                                console.log(v)
                                                val+= '<span class="col-3-1">'+v.areaName+':'+v.distributionPrice+'元</span>';

                                            })
                                        }
                                    }else {
                                        if(row[6] && row[6].length>0){
                                            $.each(row[6],function(k,v){
                                                console.log(v)
                                                val+= '<span class="col-3-1">'+v.areaName+':'+v.price+'元</span>';

                                            })
                                        }
                                    }

                                    return val;
                                },
                                "targets": 6
                            },
                            {
                                "render": function(data, type, row, meta) {
                                    if(row[10]!=0){
                                        var val = '<span><td><input style="width: 50px;" type="text" value="'+row[10]+'"></td>&nbsp;<td><a class="powerButton 244" onclick="Cloes(\''+row[8]+'\',\''+row[9]+'\',\''+row[0]+'\',this)">修改</a></td></span>';
                                        return val;
                                    }else {
                                        var val = '<span><td><input style="width: 50px;" type="text" value=""></td>&nbsp;<td><a class="powerButton 244" onclick="Cloes(\''+row[8]+'\',\''+row[9]+'\',\''+row[0]+'\',this)">修改</a></td></span>';
                                        return val;
                                    }
                                },
                                "targets": 8
                            },

                            {
                                "render": function (data, type, row) {
                                    var val = '<span class="powerButton 244"><a onclick="detaildelete(\''+row[9]+'\')">删除</a></span>';
                                    return val;
                                },
                                "targets": 9
                            }
                        ],
                        "fnInitComplete": function(oSettings, json) {
                            setBtnDis(0, $("#productManage"));
                            $("#datatable").on("change", '.spuId', function() {
                                var num = $(".shun").find("input[type=checkbox]:checked").length;
                                setBtnDis(num, $("#productManage"));
                            });

                        }
                    });
                };
            }
        };
        return web.doAjax( root.inter.findCategoryDiscountForPage, 'post', cust_data, succCallBack);
    }
})();

//查询
seahsdfs();
function seahsdfs() {
    $.ajax({
        url:root.inter.findCategoryDiscountForPage,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            pageNum:1,
            pageSize:20,
            customerCode:getQueryString('customerCode'),
            contractNum:getQueryString('contractNum'),
            "modifyPriceWay":40

        },
        success: function (result) {
            detaiist(result);
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.inter.findCategoryDiscountForPage,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        async:false,
                        data: {
                            pageNum:api.getCurrent(),
                            pageSize:20,
                            customerCode:getQueryString('customerCode'),
                            contractNum:getQueryString('contractNum'),
                            "modifyPriceWay":40

                        },
                        success: function (result) {
                            detaiist(result);
                            $("#spu_all").attr("checked", false);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
/*表格渲染*/
var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];

function detaiist(data) {

    newdata=data
    dataSource.splice(0, dataSource.length);//清空数组
    if(data.data.result!=""){
        $.each(data.data.result, function (i, field) {
            var rowData = new Array();
            rowData.push(field.productCode);
            rowData.push(field.imgUrl);
            rowData.push(field.brand);
            rowData.push(field.productName);
            rowData.push(field.saleAttriValue);
            rowData.push(field.areaName);
            rowData.push(field.prices);
            rowData.push(field.unitName);
            rowData.push(field.modifyPriceWay);
            rowData.push(field.contractCategoryDiscountId);
            rowData.push(field.categoryDiscount);
            dataSource.push(rowData);
        });
    }

    initDataTable(dataSource);

    function initDataTable(dataSource) {
        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "order": [[ 1, "desc" ]],
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": [5, 10, 25, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = '<span><td><input class="spuId" type="checkbox" name="spuId" value = "' + row[9] + '">' + row[0] + '</td></span>';
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val =""
                        if(row[1]!=""){
                            val = "<img style='width: 50px; height:50px;' onclick=picShow('查看图片','../../html/goods/picShow.html','"+row[1]+"','500','300','110') src='"+row[1]+"'>";

                        }else {
                            val =""
                        }

                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = '';
                        if(customerTypes=='商店'){

                        if(row[6] && row[6].length>0){
                            $.each(row[6],function(k,v){
                                console.log(v)
                                 val+= '<span class="col-3-1">'+v.areaName+':'+v.distributionPrice+'元</span><br>';

                            })
                        }
                        }else {
                            if(row[6] && row[6].length>0){
                                $.each(row[6],function(k,v){
                                    console.log(v)
                                    val+= '<span class="col-3-1">'+v.areaName+':'+v.price+'元</span><br>';

                                })
                            }
                        }

                        return val;
                    },
                    "targets": 6
                },
                {
                    "render": function(data, type, row, meta) {
                        if(row[10]!=0){
                            var val = '<span><td><input style="width: 50px;" type="text" value="'+row[10]+'"></td>&nbsp;<td><a onclick="Cloes(\''+row[8]+'\',\''+row[9]+'\',\''+row[0]+'\',this)">修改</a></td></span>';
                            return val;
                        }else {
                            var val = '<span><td><input style="width: 50px;" type="text" value=""></td>&nbsp;<td><a onclick="Cloes(\''+row[8]+'\',\''+row[9]+'\',\''+row[0]+'\',this)">修改</a></td></span>';
                            return val;
                        }


                    },
                    "targets": 8
                },

                {
                    "render": function (data, type, row) {
                        var val = '<span class="powerButton 244"><a onclick="detaildelete(\''+row[9]+'\')">删除</a></span>';
                        return val;
                    },
                    "targets": 9
                }
            ],
            "fnInitComplete": function(oSettings, json) {
                setBtnDis(0, $("#productManage"));
                $("#datatable").on("change", '.spuId', function() {
                    var num = $(".shun").find("input[type=checkbox]:checked").length;
                    setBtnDis(num, $("#productManage"));
                });

            }
        });
    };
    //权限控制函数
    power()
}
//图片放大
function picShow(title, url, imgUrl) {
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
    sessionStorage.setItem("imgUrl", imgUrl);
    layer_show(title, url, "800", "500");
}



//一级二级三级
function goodslistCategory(categoryLevel) {
    console.log($("#class1").val())
    var categoryName = $("#class1").val();
    var user_data = {
        categoryLevel: categoryLevel,
        categoryName: $("#class1").val(),
    }
    var succCallBack = function(data, status, response) {
        console.log("一级")
        console.log(data)
        if(data.errorCode == "0") {
            if(data.data == null) {
                classStr = "<li>无数据</li>"
                $("#classUl1").html(classStr);
            } else {
                var classStr = "";
                for(var i = 0; i < data.data.length; i++) {
                    classStr += "<li onclick='nextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                }
                $("#classUl1").html(classStr);
            }
        }
    }
    web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
}

//获取光标
$("#class1").focus(function() {
    $("#classUl1").show();
    goodslistCategory(1);
});
$(document).bind("click", function(e) {
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#classUl1").length == 0 && $(e.target).closest("#class1").length == 0) {
        //点击id为menu之外且id不是不是open，则触发
        $("#classUl1").hide()
        $("#class2").val();

    }
});
var oneCategoryId = "";
var twoCategoryId = "";
var threeCategoryId = "";
var goodslist_cantegory_id; //定义分类搜索条件
// 2,3,4级的模糊查询
function getNext_input(level, category_id) {
    console.log(category_id)
    if(level == 2) {
        console.log(category_id+'一级')
        oneCategoryId = category_id;
    } else if(level == 3) {
        console.log(category_id+'二级')
        twoCategoryId = category_id;
    } else if(level == 4) {
        console.log(category_id+'三级')
        threeCategoryId = category_id;
    }
    if(level == 4) {
        goodslist_cantegory_id = category_id;
    }
    if(level < 4) {
        console.log(level)
        $("#class" + level + "")[0].oninput = function() {
            var user_data = {
                parentCateId: category_id,
                categoryName: $("#class" + level + "").val()
            }
            var succCallBack = function(data, status, response) {
                console.log("二级")
                console.log(data)
                if(data.errorCode == 0) {
                    if(data.data == null) {
                        classStr = "<li>无数据</li>";
                    } else {
                        var classStr = "";
                        for(var i = 0; i < data.data.length; i++) {
                            classStr += "<li onclick='nextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                        }
                    }
                    if(data.data[0] == undefined) {
                        classValue = category_id;
                        var nextLevel = level + 1;
                        $("#classUl" + nextLevel + "").html(classStr);
                        $("#classUl" + level + "").hide();
                    } else {
                        var nextLevel = data.data[0].category_level;
                        $("#classUl" + nextLevel + "").html(classStr);
                        $("#classUl" + level + "").show();
                    }
                }
            }
            web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
        }
        //获取光标
        $("#class" + level + "").focus(function() {
            $("#classUl" + level + "").show();
        });
        $(document).bind("click", function(e) {
            //id为menu的是菜单，id为open的是打开菜单的按钮
            if($(e.target).closest("#classUl" + level + "").length == 0 && $(e.target).closest("#class" + level + "").length == 0) {
                //点击id为menu之外且id不是不是open，则触发
                $("#classUl" + level + "").hide()
            }
        });
    }

}

function nextClass(category_id, level, category_name) {
    $("#class" + level + "").val(category_name);
    if(level == 1) {
        $("#class2").val("");
        $("#class3").val("");
    } else if(level == 2) {
        $("#class3").val("");
    }
    var user_data = {
        parentCateId: category_id,
    }
    var succCallBack = function(data, status, response) {
        console.log(data)
        if(data.errorCode == "0") {
            if(data.data == null) {
                classStr = "<li>无数据</li>";
            } else {
                var classStr = "";
                for(var i = 0; i < data.data.length; i++) {
                    classStr += "<li onclick='nextClass(" + data.data[i].category_id + "," + data.data[i].category_level + ",\"" + data.data[i].category_name + "\")'>" + data.data[i].category_name + "</li>"
                }
            }
            if(data.data[0] == undefined) {
                classValue = category_id;
                var nextLevel = level + 1;
                $("#classUl" + nextLevel + "").html(classStr);
                $("#classUl" + level + "").hide();
            } else {
                var nextLevel = data.data[0].category_level;
                $("#classUl" + nextLevel + "").html(classStr);
                $("#classUl" + nextLevel + "").show();
                $("#classUl" + level + "").hide()
            }
        }
    }
    getNext_input(level + 1, category_id);
    web.doAjax(root.goodsInter.categoryByParam, 'post', user_data, succCallBack);
}

/*品牌选择*/
function myfFunction(){
    $.ajax({
        url: root.goodsInter.goods_getListBrand,
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            brandName: $("#username").val().trim()
        },
        success: function (data) {
            console.log(data)
            var jsonObj =data.ListBrand;
            if(jsonObj==""){
                $("#tudfan").html("<li>无数据</li> ");
            }else {
                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    jsonobj1=jsonObj[i].brandId
                    brandIds=jsonObj[i].brandId
                    optionstring += "<li onclick='addCodeFun("+ jsonObj[i].brandId+ ",\""+jsonObj[i].brandName+ "\")'>"+jsonObj[i].brandName+ "</li>";
                }
                $("#tudfan").html(optionstring);
            }
        }
    });
}
//运营经理获取光标
$("#username").focus(function () {
    $("#tudfan").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tudfan").length == 0 && $(e.target).closest("#username").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tudfan").hide()
    }
})
var brandName = "";
var brandId = "";
function addCodeFun(id,brand_name) {
    $("#tudfan").hide();
    $("#username").val(brand_name)
    brandName = brand_name;
    brandId = id;
}
function brand_sure() {
    sessionStorage.setItem("brand_name",brandName);
    sessionStorage.setItem("brand_id",brandId);
    $("#selectInp").css({
        display:"none"
    });
    addBrandName();
}
//渲染品牌名称
function addBrandName() {
    if(sessionStorage.getItem("brand_name")){
        $("#brandName").html(sessionStorage.getItem("brand_name"));
        $("#brandId").html(sessionStorage.getItem("brand_id"));
    }
}
//渲染属性名称
function addAttrName() {
    console.log(sessionStorage.getItem("attrObjCanch")+"##########");
    if(sessionStorage.getItem("attrObjCanch")){
        var attrObjCanch = JSON.parse(sessionStorage.getItem("attrObjCanch"));
        for(var i=0;i<attrObjCanch.length;i++){
            var attrValStr="";
            var attrIdsStr="";
            if(attrObjCanch[i].value.length != 0){
                for(var j=0;j<attrObjCanch[i].value.length;j++){
                    attrValStr += attrObjCanch[i].value[j].attri_value+";";
                    attrIdsStr +=attrObjCanch[i].value[j].attri_value_id+";";
                }
            }
            $("#appendAttr").remove();
            $("#attrTable").append('<tr id = "appendAttr"><th class="col-6-1 text-c">'+attrObjCanch[i].attribute_name+'</th><td><span>'+attrValStr+'</span><a onclick="addAttr('+attrObjCanch[i].attribute_id+",'"+attrIdsStr+"'"+')">添加</a></td></tr>')
        }
    }
}
function stoprop() {
    /*批量上架全选框阻止冒泡*/
    var timer = setTimeout(function() {
        var num = $("#datatable").find("tbody").find("input[type=checkbox]:checked").length;
        setBtnDis(num, $("#productManage"));
        clearTimeout(timer);
    }, 200)

    window.event ? window.event.cancelBubble = true : e.stopPropagation();
}
function setBtnDis(num, pnode) { //如果选中项为空时，置灰相关按钮
    if(num <= 0) {
        pnode.find(".goods_edit").attr("disabled", "disabled").addClass("dis_btn");
    } else {
        pnode.find(".goods_edit").removeAttr("disabled").removeClass("dis_btn");
    }
}

/*var customer_type = sessionStorage.getItem("customer_type");*/
var customertype=""
//修改
function Cloes(modifyPriceWay,id,skucode,el) {
    if (customerTypes=="商店"){
        customertype=10
    }else {
        customertype=20
    }
    inputmm=$(el).parent().find('input').val()
    inputid=id
    inputcode=skucode
    $.ajax({
        /*root.inter.updateBatchCategoryDiscount*/
        url:root.inter.updateBatchCategoryDiscount,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            modifyPriceWay:40,
            categoryDiscount:$(el).parent().find('input').val(),
            contractCategoryDiscountId :id,
            skuCode:skucode,
            customerType:customertype

        },
        success: function (data) {
            console.log(data)
            seahsdfs();
            if(data.errorCode==0){
                if(data.sub_code==2){
                    inputmsg=data.sub_msg
                    updamm();
                }else if(data.sub_code==3){
                    $.Huimodalalert(data.sub_msg,2000);
                }else {
                    $.Huimodalalert('修改成功！',2000);
                }

            }else {

                $.Huimodalalert(data.msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}



//修改密码
var index=0;
function updamm() {
    var cu = layer.confirm('<span>'+inputmsg+",确认修改请输入密码"+'</span><input class="input-text radius" placeholder="请输入密码" type="password" style="padding-left: 10px;" id="remarksr">', {title:'提示',btn: ['确认', '取消']}, function(index){
        fini3()
        layer.close(cu);
    },function(){
        layer.close(cu);

    });
}
//第二个
function fini3(){
    var remarksr = $("#remarksr").val();
    console.log(remarksr)

    $.ajax({
        url:root.orderInter.checkPriceRevisionPwd,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            password:$("#remarksr").val().trim()
        },
        success: function (data) {
            if(data.data==10){
                if (customerTypes=="商店"){
                    customertype=10
                }else {
                    customertype=20
                }
                $.ajax({
                    url:root.inter.updateCategoryDiscountBelowCostPrice,
                    cache: false,  //禁用缓存
                    type: "POST",
                    dataType:'json',
                    async:false,
                    data: {
                        modifyPriceWay:40,
                        categoryDiscount:inputmm,
                        contractCategoryDiscountId :inputid,
                        skuCode:inputcode,
                        customerType:customertype

                    },
                    success: function (data) {
                        console.log(data)
                        if(data.errorCode==0){
                            seahsdfs();
                            // location.replace(location.href)
                        }else {

                            $.Huimodalalert(data.msg,2000);
                        }

                    },
                    error: function () {
                        $.Huimodalalert('失败！',2000);
                    }
                })
            }else {
                $.Huimodalalert(data.sub_msg,2000);
            }


        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })


    layer.close(index);
}
//单个删除
function detaildelete(id) {
    console.log(id);
    var objArr = [];
    if (id.indexOf(",") != -1) {
        var split = id.split(",");
        for (var i = 0; i < split.length; i++) {
            objArr.push(Number(split[i]));
        }
    } else {
        objArr.push(id);
    }
    console.log(JSON.stringify(objArr))
    $.ajax({
        url:root.inter.delBatchCategoryDiscountByList,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify(objArr),
        success: function (data) {

            if(data.errorCode==0){
                $.Huimodalalert('删除成功！',2000);
                $("#spu_all").attr("checked",false);
                seahsdfs();
            }else {
                $.Huimodalalert(data.msg,2000);
            }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })
}
//批量删除
function deleteyy() {
    var spuIdArr=document.getElementsByName('spuId');
    var str=""
    for(var i=0; i < spuIdArr.length;i++){
        if(spuIdArr[i].checked==true){
            str+= spuIdArr[i].value+','
        }
    }
    str = str.substring(0, str.length - 1);
    detaildelete(str)

}
/*//类目导入
function importCategoryFn() {
    console.log("类目导入")
}
//失败信息下载
function failInfoDownloadFn() {
    console.log("失败信息下载")
}*/
//查询结果页
function queryresults() {
    console.log($("#class1").val())
    var oneCategoryIds=""
    if($("#class1").val()==""){
        oneCategoryIds=""
    }else {
        oneCategoryIds=oneCategoryId
    }
    var twoCategoryIds=""
    if($("#class2").val()==""){
        twoCategoryIds=""
    }else {
        twoCategoryIds=twoCategoryId
    }
    var threeCategoryIds=""
    if($("#class3").val()==""){
        threeCategoryIds=""
    }else {
        threeCategoryIds=threeCategoryId
    }
    $.ajax({
        url:root.inter.findContractCategoryDiscountByCondition,
        contentType: "application/json;charset=UTF-8",
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data: JSON.stringify({
            "pageNum":1,
            "pageSize":20,
            "spuCode":$("#spuCode").val().trim(),
            "productName":$("#spuName").val().trim(),
           /* "skuCode":$("#skuCode").val().trim(),*/
            "helpCode":$("#helpCode").val().trim(),//助记码
            "productCode":$("#Code").val().trim(),
            "customerCode":getQueryString('customerCode'),
            "contractNum": getQueryString('contractNum'),

        }),
        success: function (result) {
            detaiist(result);
            $('.M-box3').pagination({
                pageCount: result.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.inter.findContractCategoryDiscountByCondition,
                        contentType: "application/json;charset=UTF-8",
                        ccache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        data: JSON.stringify({
                            "pageNum":api.getCurrent(),
                            "pageSize":20,
                            "spuCode":$("#spuCode").val().trim(),
                            "productName":$("#spuName").val().trim(),
                          /*  "skuCode":$("#skuCode").val().trim(),*/
                            "helpCode":$("#helpCode").val().trim(),//助记码
                            "productCode":$("#Code").val().trim(),
                            "customerCode":getQueryString('customerCode'),
                            "contractNum": getQueryString('contractNum'),
                        }),
                        success: function (result) {
                            detaiist(result);
                            $("#spu_all").attr("checked", false);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//搜索
function ditailquery(title,url) {
    if($("#spuCode").val().trim()!=""||$("#Code").val().trim()!=""||$("#helpCode").val().trim()!=""||$("#spuName").val().trim()!=""||$("#skuName").val().trim()!=""){
        sessionStorage.setItem("threeCategoryId",threeCategoryId);
        sessionStorage.setItem("brandid",jsonobj1);
        sessionStorage.setItem("spuCode",$("#spuCode").val().trim());
        sessionStorage.setItem("Code",$("#Code").val().trim());
        sessionStorage.setItem("helpCode",$("#helpCode").val().trim());
        sessionStorage.setItem("spuName",$("#spuName").val().trim());
        sessionStorage.setItem("skuName",$("#skuName").val().trim());

        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }else {
        $.Huimodalalert('请填写详细信息！',2000);
    }



}

